package com.zho.util;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public final class ObjectCopy {

	private ObjectCopy() {
	}

	public static Object copy(Object obj) {
		if (obj == null)
			return null;
		Object clone = null;
		try {
			ByteArrayOutputStream bos = new ByteArrayOutputStream();
			ObjectOutputStream oos = new ObjectOutputStream(bos);
			oos.writeObject(obj);
			oos.close();
			ObjectInputStream ois = new ObjectInputStream(
					new ByteArrayInputStream(bos.toByteArray()));
			clone = ois.readObject();
			ois.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return clone;
	}
}
